package com.cy.service.Impl;

import com.cy.Dao.LogDao;
import com.cy.Pojo.Log;
import com.cy.common.Exception.ServiceException;
import com.cy.service.LogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//@Slf4j
@Service
public class LogImpl implements LogService {
    //初始化日志对象，门面模式
    private static final Logger loog= LoggerFactory.getLogger(LogImpl.class);//==>>>>>>>Slf4j
    @Autowired
    private LogDao logDao;

    @Override
    public List<Log> findLog(Log log) {
        long stime=System.currentTimeMillis();
        loog.info("method start {}",stime);
        List<Log>list=logDao.SelectLog(log);
        long etime=System.currentTimeMillis();
        loog.info("method end {}",etime);

        return list;
    }

    @Override
    public Log findLogById(Long id) {
        Log log=logDao.selectLogById(id);
        if(log==null)
            throw new ServiceException("该纪录不存在");
        return log;
    }

    @Override
    public int saveLog(Log log) {
        return logDao.InsertLog(log);
    }

    @Override
    public int deleteLog(int... id) {
       int lows=logDao.DeleteLog(id);
      if(lows==0)
          throw new ServiceException("该纪律已经起飞");
        return lows;
    }
    /**
     * 可以Autowired注入，也可以用构造方法注入；
     *
    public LogImpl(LogDao logDao){
       this.logDao=logDao;
   }
     */

}
